import { Router } from 'express';
import dashboardController from '@controllers/dashboard.controller';
import { authenticate } from '@middleware/auth';

const router = Router();

/**
 * Dashboard Routes
 */

/**
 * @swagger
 * /dashboard/overview:
 *   get:
 *     summary: Get dashboard overview statistics
 *     tags: [Dashboard]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: Dashboard overview retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: object
 *                   properties:
 *                     alerts:
 *                       type: object
 *                       properties:
 *                         total:
 *                           type: number
 *                         active:
 *                           type: number
 *                         resolved:
 *                           type: number
 *                     tickets:
 *                       type: object
 *                       properties:
 *                         total:
 *                           type: number
 *                         open:
 *                           type: number
 *                         inProgress:
 *                           type: number
 *                         resolved:
 *                           type: number
 *                     services:
 *                       type: object
 *                       properties:
 *                         total:
 *                           type: number
 *                         healthy:
 *                           type: number
 *                         unhealthy:
 *                           type: number
 *       401:
 *         description: Unauthorized
 */
router.get('/overview', authenticate, dashboardController.getOverview);

/**
 * @swagger
 * /dashboard/recent-alerts:
 *   get:
 *     summary: Get recent alerts
 *     tags: [Dashboard]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: Number of recent alerts to return
 *     responses:
 *       200:
 *         description: Recent alerts retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: string
 *                       alertname:
 *                         type: string
 *                       severity:
 *                         type: string
 *                       status:
 *                         type: string
 *                       startsAt:
 *                         type: string
 *                         format: date-time
 *       401:
 *         description: Unauthorized
 */
router.get('/recent-alerts', authenticate, dashboardController.getRecentAlerts);

/**
 * @swagger
 * /dashboard/services:
 *   get:
 *     summary: Get services status
 *     tags: [Dashboard]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: Services status retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       name:
 *                         type: string
 *                         example: API Gateway
 *                       status:
 *                         type: string
 *                         enum: [healthy, unhealthy, degraded]
 *                         example: healthy
 *                       uptime:
 *                         type: number
 *                         example: 99.9
 *                       responseTime:
 *                         type: number
 *                         example: 45
 *       401:
 *         description: Unauthorized
 */
router.get('/services', authenticate, dashboardController.getServicesStatus);

/**
 * @swagger
 * /dashboard/performance:
 *   get:
 *     summary: Get performance metrics
 *     tags: [Dashboard]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: timeRange
 *         schema:
 *           type: string
 *           enum: [1h, 6h, 24h, 7d, 30d]
 *           default: 24h
 *         description: Time range for performance metrics
 *     responses:
 *       200:
 *         description: Performance metrics retrieved successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 data:
 *                   type: object
 *                   properties:
 *                     cpu:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           timestamp:
 *                             type: string
 *                           value:
 *                             type: number
 *                     memory:
 *                       type: array
 *                       items:
 *                         type: object
 *                     responseTime:
 *                       type: array
 *                       items:
 *                         type: object
 *       401:
 *         description: Unauthorized
 */
router.get('/performance', authenticate, dashboardController.getPerformanceMetrics);

export default router;
